
package utils;

import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

/**
 * Class used to display errors appends during Telnet/SSh connection
 */
public class connectionErrorWindow extends JFrame
	{
	/**
	 * Variables
	 */
	private ArrayList<String> error;
	
	//Disposition
	private JPanel listAXLRequest;
	private JScrollPane scrollbar;
	private JPanel Principale;
	
	/***
	 * Constructeur
	 */
	public connectionErrorWindow(ArrayList<String> error)
		{
		super("Connection Error Window");
		this.error = error;
		buildWindow();
		}
	
	public void buildWindow()
		{
		//Disposition
		this.setSize(new Dimension(600,200));
		new Centrer(this);
		this.setBounds(this.getX()+200, this.getY()-100, this.getWidth(), this.getHeight());
		Principale = new JPanel();
		
		this.getContentPane().setLayout(new BoxLayout(this.getContentPane(),BoxLayout.Y_AXIS));
		Principale.setLayout(new BoxLayout(Principale,BoxLayout.Y_AXIS));
		listAXLRequest = new JPanel();
		listAXLRequest.setLayout(new BoxLayout(listAXLRequest,BoxLayout.Y_AXIS));
		listAXLRequest.setPreferredSize(new Dimension(500,175));
		scrollbar = new JScrollPane(listAXLRequest);
		
		//Assignation
		Principale.add(new JLabel("Les erreurs suivantes se sont produites au cours de la configuration telnet/SSH :"));
		Principale.add(scrollbar);
		this.getContentPane().add(Principale);
		
		remplissage();
		this.setVisible(true);
		}
	
	/***********************************************
	 * Methode qui remplie le centre de la fenetre
	 * avec une ligne pour chaque device
	 ***********************************************/
	
	public void remplissage()
		{
		try
			{
			listAXLRequest.removeAll();
			for(int i=0; i<error.size(); i++)
				{
				String[] tab = error.get(i).split(":");
				String first = tab[0]+":"+tab[1]+":";
				System.out.println("###"+error.get(i));
				JPanel myPane = new JPanel();
				myPane.setBackground((i%2==0)?Color.WHITE:Color.LIGHT_GRAY);
				myPane.setLayout(new BoxLayout(myPane,BoxLayout.X_AXIS));
				myPane.add(new JLabel(first));
				myPane.add(Box.createHorizontalGlue());
				StringBuffer reason = new StringBuffer("");
				for(int j=2; j<tab.length; j++)
					{
					reason.append(tab[j]);
					}
				myPane.add(new JLabel(reason.toString()));
				listAXLRequest.add(myPane);
				}
			this.repaint();
			this.validate();
			}
		catch(Exception exc)
			{
			exc.printStackTrace();
			variable.getLogger().error(exc);
			}
		}
	
	
	/*2013*//*RATEL Alexandre 8)*/
	}